package ar.com.mooral.activities;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import ar.com.mooral.crohn.application.CrohnContext;

public class Grafica extends CrohnActivity {
	
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        
        try {
	    	WebView webview = new WebView(this);
	    	setContentView(webview);
	    	
	    	String periodRange = CrohnContext.getPeriodo();
	    	
	    	String url = "http://82.223.107.224:8080/ServidorCrohnAlDia/generaGraficaAndroid.action?paciente=" + CrohnContext.getPatientCode() + "&periodo=" + periodRange;
	    	
	    	if (periodRange.equals("5")) {
	    		String minRange = CrohnContext.getRecordsMinRange();
	    		String maxRange = CrohnContext.getRecordsMaxRange();
	    		
	    		
				SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
				Date dateMinRange = (Date)formatter.parse(minRange);
				Date dateMaxRange = (Date)formatter.parse(maxRange);
	   
		    	SimpleDateFormat urlFormatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
		    	
	    		url += "&fechaInicio=" + (String) urlFormatter.format(dateMinRange) + "&fechaFin=" + (String) urlFormatter.format(dateMaxRange);
	    	} 
	    	
	    	//url = "http://chart.apis.google.com/chart?cht=bvg&chs=250x150&chd=s:Monkeys&chxt=x,y&chxs=0,ff0000,12,0,lt|1,0000ff,10,1,lt";	    	
	    	webview.loadUrl(url);
	    	
        } catch (Exception e) {
        	Log.e("CROHN", e.toString());
        }
        
    }	

}
